﻿@model IEnumerable<Db8.Data.Claim>
@{
    ViewBag.Title = "Search";
}
<section class="content">
<div style="float:right">@Html.Partial("_Navigation")</div>
<div style="float:left">@Html.Partial("_Search")</div>
<div style="clear:both;"></div>

    <br />

    @foreach (var item in Model)
    {
        <div class="claim-box">
            <div class="false-claim-search-label">
            @Html.DisplayFor(modelItem => item.Statement)
            </div>
            <div class="counter-claims claim-list">
            @foreach (var counterClaim in item.CounterClaims)
            {
                <div>
                    <input type="checkbox" name="CounterClaim" id="chk-@counterClaim.ClaimId" value="@item.ClaimId/@counterClaim.ClaimId" class="styled" /><label for="chk-@counterClaim.ClaimId" class="editor-field">@Html.DisplayFor(modelItem => counterClaim.Claim.Statement)</label>
                </div>
            }
            </div>
        </div>
    }
</section>
@section scripts {
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.validate.min.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/db8-ui.js")"></script>
<script type="text/javascript">

    $(function () {

        var rsp = $.getCookie("rsp");
        if (!rsp) {
            $.setCookie("rsp", "", 30);
            rsp = "";
        }

        $.each(rsp.split("|"), function (idx, value) {
            $("[value='" + value + "']").each(function () {
                $(this).prop("checked", true);
            });
        });

        $("input[name='CounterClaim']").click(function () {
            var checkbox = $(this);
            if (checkbox.is(":checked")) {
                //alert("check");
                if (rsp.indexOf(checkbox.val()) == -1) {
                    if (rsp == "")
                        rsp = checkbox.val();
                    else
                        rsp = rsp + "|" + checkbox.val();
                }
            } else {
                //alert("uncheck");
                if (rsp.indexOf(checkbox.val()) >= -1) {
                    var a = rsp.split("|");
                    var index = -1;
                    $.each(a, function (idx, value) { if (value == checkbox.val()) index = idx; });
                    if (index > -1)
                        a.splice(index, 1);
                    rsp = a.join("|");
                }
            }
            $.setCookie("rsp", rsp, 30);
        });
    });

</script>
}